<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/actions/admin/AdminAction.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/actions/Response.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/model/Service/Service.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/model/Service/ServiceFactory.php';

final class EmployeeDeleteAction extends AdminAction {
	protected function execute(Response $response) {
		if(isset($_POST['identity'])) {
			$serviceFactory = new ServiceFactory();
			$service = $serviceFactory->getService('EmployeeService');
			$employee = $service->read($_POST['identity']);
			if($employee !== null) {
				$service->delete($_POST['identity']);
				$_SESSION['person-identity'] = $employee->getPerson()->getIdentity();
				$response->setActionPath('/person/edit.html');
			}
		}
		if($response->getActionPath() === null) {
			$response->setActionPath('/person/index.html');
		}
	}
}
?>